import { http } from '@/utils/http'
import { AppThunk } from '../index'
import { getChannelsList, getArticleList } from '../modules/article'
/**
 * 获取文章频道列表
 * @param payload 
 * @returns 
 */
export const getChannelsAction = (payload?: unknown): AppThunk => {
  return async (dispatch, getState) => {
    const { data } = await http.get('/channels')
    // console.log(data.data.channels)
    dispatch(getChannelsList(data.data.channels))
  }
}
export type Params = {
  status?: number
  channel_id?: number
  begin_pubdate?: string
  end_pubdate?: string
  total?: number
  page?: number
  per_page?: number
}
export const getArticleAction = (params: Params): AppThunk => {
  return async (dispatch, getState) => {
    const { data } = await http.get('/mp/articles', {
      params
    })
    // console.log(data.data)
    dispatch(getArticleList(data.data))
  }
}
export const delArticleAction = (id: string): AppThunk => {
  return async (dispatch, getState) => {
    await http.delete('/mp/articles/' + id)
    // console.log(data.data)
  }
}